#ifndef PERSONSTABLE_H_
#define PERSONSTABLE_H_

#include <list>
#include "SharedMemory.h"
#include "TableFile.h"
#include "TableRecord.h"
#include "Constants.h"
#include "Semaphore.h"

class PersonsTable {
private:
	unsigned int sharedMemoryCounter;
	bool tableLoaded;
	list< SharedMemory<TableRecord> > records;
	Semaphore* dbAccess;
	Semaphore* counterAccess;
	Semaphore* orderAccess;
	unsigned int readersCounter;
	static bool compareSharedMemory(SharedMemory<TableRecord>& leftItem, SharedMemory<TableRecord>& rightItem);
	long getNewId();
	
public:
	PersonsTable();
	virtual ~PersonsTable();
	void loadTableFromFile();
	void persistTableToFile();
	int addRecord(TableRecord record);
	list<TableRecord> getRecords();
	TableRecord getRecord(long id);
	TableRecord deleteRecord(long id);
	bool isTableLoaded();
};

#endif /* PERSONSTABLE_H_ */
